version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220619          // set seed

*-------------------------------------------------------
* project: daylight saving time (dst)
*-------------------------------------------------------

local pgm  "dst-data01_counties_2020_clean" // file name
local who  "Muzhe Yang"                     // author
local dte  "2022-06-19"                     // created date
local dte2 "`c(current_date)'"              // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\management\\`pgm'.txt", replace text
display "`tag'"

import delimited "data_raw\counties\Gaz_counties_national_2020.txt", stringcols(2 3) asdouble case(upper) clear

* For descriptions of variables, see below:
* https://www.census.gov/programs-surveys/geography/technical-documentation/records-layout/gaz-record-layouts.2020.html

drop ANSICODE ALAND AWATER ALAND_SQMI AWATER_SQMI
rename USPS      state
rename NAME      county
rename INTPTLAT  county_lat 
rename INTPTLONG county_lon

label variable GEOID       "state fips + county fips"
label variable state       "state name abbreviation"
label variable county      "county name"
label variable county_lat  "latitude of the county's centroid"
label variable county_lon  "longitude of the county's centroid"

order GEOID GEOID state county county_lat county_lon
sort GEOID
codebook, compact
compress
save "data_clean\counties\\`pgm'.dta", replace 

log close
exit